package cn.lg.soar.boot.fc.dao.impl;

import cn.lg.soar.boot.fc.dao.ExtendFieldDao;
import cn.lg.soar.boot.fc.dao.ExtendFieldRepository;
import cn.lg.soar.boot.fc.pojo.ExtendField;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Component
public class ExtendFieldDaoImpl implements ExtendFieldDao {

	@Resource
	private ExtendFieldRepository repository;
	
	@Override
	public void save(ExtendField extendField) {
		repository.save(extendField);
		
	}

	@Override
	public List<ExtendField> findAll() {
		List<ExtendField> list = repository.findAll();
		return list;
	}

	@Override
	public List<ExtendField> findList(ExtendField extendField) {
		Sort sort = Sort.by(Sort.Direction.ASC,"orderNum");
		Example<ExtendField> example = Example.of(extendField);
		List<ExtendField> list = repository.findAll(example,sort);
		return list;
	}

    /**
     * 根据id查询所有信息
     * @param id
     */
    @Override
    public void deleteById(String id) {

		repository.deleteById(id);
    }

    /**
     * 根据id查询所有信息
     * @param ids
     */
    @Override
    public void deleteByIds(String ids) {
    	String[] idArr = ids.split(",");
    	for (String id : idArr) {
    		repository.deleteById(id);
		}
    }

    /**
     * 根据id查询所有信息
     * @param id
     */
    @Override
    public ExtendField findById(String id) {
    	Optional<ExtendField> extendField = repository.findById(id);
        return extendField.get();
    }

}
